<?php
slot ( 'title', 'Deadline Calendar' );
?>
<?php slot ('header')?>
<h1>Deadline Calendar</h1>
<?php end_slot()?>
<?php slot ('side_bar') ?>
<h2>View</h2>
<ul>
    <li><?php echo link_to('Calendar', '@planning_calendar_no_dates?pr_slug='.$prSlug);?></li>
    <li><?php echo link_to('List', '@planning_list?pr_slug='.$prSlug )?></li>
    <li><?php echo link_to('Gantt Chart', '@planning_chart?pr_slug='.$prSlug)?></li>
</ul>
<h2>Search</h2>
<ul>
    <li><?php echo link_to('Search', '@planning_search?pr_slug='.$prSlug )?></li>
</ul>
<h2>Deadlines</h2>
<ul>
    <li><?php echo link_to('Add', '@planning_create?pr_slug='.$prSlug )?></li>
</ul>
<?php end_slot() ?>

<div id="plan">
     <?php
	// Echo actual html.
	echo "<table border=1 width=800 height=600>";//$dueBefore/$importance/$group/$createdBy
	echo "<tr><th colspan=7 align=center> <a href=\"".url_for("@planning_calendar?pr_slug=$prSlug&month=$prev_month&year=$prev_year")."\"> <big><big><<</big></big> </a>";
	echo "<big><big> $title $year </big></big>";
    echo "<a href=\"".url_for("@planning_calendar?pr_slug=$prSlug&month=$next_month&year=$next_year")."\"> <big><big>>></big></big> </a></tr>";
	echo "<tr><td width=100 height=12 align=center><b>S</b></td><td width=100 align=center><b>M</b></td><td width=100 align=center><b>T</b></td><td width=100 align=center><b>W</b></td><td width=100 align=center><b>T</b></td><td width=100 align=center><b>F</b></td><td width=100 align=center><b>S</b></td></tr>";
	// Count days up to 7.
	$day_count = 1;
	echo "<tr height=125>";
	// Fill blank days.
	while ( $blank > 0 ) {
		echo "<td></td>";
		$blank = $blank - 1;
		$day_count ++;
	}
	// Start at day 1.
	$day_num = 1;
	// Fill to month is done.
	while ( $day_num <= $days_in_month ) {
		echo "<td valign=\"top\">";
		echo $day_num;
		echo "<br/>";
		$timestamp = strtotime("$year-$month-$day_num");
		$prev_day = $timestamp - 12*60*60;
        $next_day = $timestamp + 12*60*60;;
        /*echo "$timestamp<br/>";
        echo "$prev_day<br/>";
        echo "$next_day<br/>";
        echo strtotime($projList[0]->getDueDate());*/
        if (count($deadList) > 0)
        {
			foreach ($deadList as $dead)
			{ 
			  if (strtotime($dead->getDueDate()) > $prev_day && (strtotime($dead->getDueDate()) < $next_day) && ($dead->searched($group, $dueBefore, $importance, $createdBy)))
			      echo link_to($dead->getTitle(),'@planning_edit?pr_slug='.$prSlug.'&id='.$dead->getID()).'<br>';
			}
	   }
		echo "</td>";
		$day_num ++;
		$day_count ++;
		if ($day_count > 7) {
			echo "</tr><tr height=125>";
			$day_count = 1;
		}
	}
	//Finaly we finish out the table with some blank details if needed
	while ( $day_count > 1 && $day_count <= 7 ) {
		echo "<td></td>";
		$day_count ++;
	}
	echo "</tr></table>";?>
</div>
